package thread;

import java.util.concurrent.locks.ReentrantLock;

public class Ticket implements Runnable {
	//共100票
	int ticket = 100;

	@Override
	public void run() {
	
		//模拟卖票
		while(true){
			if(ticket==0){
				break;
			}
			abc();
		}
	}
//同步方法
	private synchronized void abc() {
		if (ticket > 0) {
			//模拟选坐的操作
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName() + "正在卖票:" + ticket--);
		}
	}
	}
